<style>
.yes{
	color: #1BBC9D;
    cursor: pointer;
}
.no{
	color: #9ea3a7;
    cursor: pointer;
}
</style>
<{include file="tpl/filter.tpl"}>

<div>
	<{if $type == 1 }>
		<a class="label-success pull-right" style="color: #fff; padding: 0 4px;" href="<{PubFunc::buildUrl('/oss/?r=resource/add&type=1')}>">
            <i class="fa fa-plus"></i> 上传资源文件(正式)
        </a>
	<{/if}>
		
	<{if $type == 2 }>
		<a class="label-success pull-right" style="color: #fff; padding: 0 4px;" href="<{PubFunc::buildUrl('/oss/?r=resource/add&type=2')}>">
            <i class="fa fa-plus"></i> 上传资源文件(测试)
        </a>
	<{/if}>
		
	<{if $type == 3 }>
		<a class="label-success pull-right" style="color: #fff; padding: 0 4px;" href="<{PubFunc::buildUrl('/oss/?r=resource/add&type=3')}>">
            <i class="fa fa-plus"></i> 上传资源文件(审核)
        </a>
	<{/if}>
		
    
</div>

<{include file="tpl/grid.tpl"}>
	

<script>
    $(function(){
        
        $(document).on('click','.changeVisible',function(){
        	if($(this).hasClass('no')){
        		var val = 2; // 无效
        	}else if($(this).hasClass('yes')){
        		var val = 1; //有效
        	}
        	var _this = $(this);
        	var id = $(this).attr('data-id');
        	
        	if(val == 2){
        		layer.confirm('确定修改状态!', {
        			btn: ['确定','取消'] //按钮
        		}, function(){
        			var g = $("input[name='g']").val();
        	        var url = '?r=resource/change_visable&g='+g;
        	        $.ajax({
        	        	type : 'POST',
    			        url : url,
				        data : {'id':id,'val':val},
				        dataType :'JSON',
				        success : function(res){
				        	if(res.status == 1){
				        		if(_this.hasClass('no')){
				        			_this.removeClass('no');
						            _this.addClass('yes');
						            _this.html("<i class='fa fa-check-circle'></i>有效");
        	                    }else if(_this.hasClass('yes')){
        	           	            _this.removeClass('yes');
						            _this.addClass('no');
						            _this.html("<i class='fa fa-ban'></i>无效");
        	                    }
						        layer.msg(res.msg, {icon: 1});
					        }else{
						        layer.msg(res.msg, {icon: 2,time: 2000});
					        }
				        }
			        });
        		}, function(){
        			//取消
                });
        	}
        	
        	if(val == 1){
        		layer.msg('不能进行修改!', {icon: 2,time: 2000});
        		return false;
        	}
        	
        	
        });
        
    });
    
</script>




<script>
	    $(document).on('click','a[name="setting_automatic"]',function(){
	    	var ids = $(this).attr('data-id'); 
            version_update_one(ids);      	
        }); 
        
        
        function version_update_one(ids){       	                   
            var data_url = '?r=resource/settingAutomatic';
            var g = $("input[name='g']").val();
            
            var url = data_url+'&g='+g;
    		layer.open({
    		    skin: 'layui-layer-molv'
    		    ,btn: ['取消', '确定']
    			,type: 2
    			,area: ['360px', '450px']
    			,title:'设置状态修改时间'
    			,content: url
    			,yes: function(index, layero){
                   //按钮【按钮一】的回调
                   layer.close(index);
                   
                }
                ,btn2: function(index, layero){
                   //按钮【按钮二】的回调
                    var iframeWin = window["layui-layer-iframe" + index];
                    var arr = iframeWin.callbackdata();
                    console.log(arr);
                    if(arr[0] == ''){
                   	   layer.msg('请设置状态自动修改时间', {icon: 2,time: 3000});
                   	   return false;
                    }

                    var automatic_time = arr[0];
                   
                    $.ajax({
                   	    type : 'POST',
    		            url : url,
			            data : {'ids':ids,'automatic_time':automatic_time},
			            dataType :'JSON',
			            success : function(res){
				            if(res.status == 1){
				    	        layer.alert('操作完成', {
				        	      skin: 'layui-layer-molv' //样式类名
						          ,closeBtn: 0
					            }, function(){
						          window.location.reload();
					            }); 
				            }else{
					           layer.alert(res.msg, {icon: 2, skin: 'layui-layer-molv'});
					           return false;
				            }
			            }
		            });	

                   //return false 开启该代码可禁止点击该按钮关闭
                },cancel: function(){ 
                   //右上角关闭回调
                   //return false 开启该代码可禁止点击该按钮关闭
                }
    		});
        }
</script>


